// packageE/appointment/mine/mine.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mine: {},
    carousels: [],
    projects: [],
    workers: [],
    appointmentLang: {},
    imgPath: app.globalData.imgPath,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      appointmentLang: wx.getStorageSync('yz_basic_info').lang.appointment
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMine();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  async toAppointmentApplyClass() {
    await this.getMine();
    if (this.data.mine.is_agent_apply.status == 1 || this.data.mine.is_agent_apply.status == 2) {
      app.tips(this.data.mine.is_agent_apply.msg);
    } else if (this.data.mine.is_agent_apply.status == 3) {
      // 去模板
      wx.navigateTo({
        url: '/mircoApp/shop_base/reward_template/index?api=' + this.data.mine.is_agent_apply.api,
      })
    } else {
      wx.navigateTo({
        url: '/packageE/appointment/Dividends/AppointmentApplyClass',
      })
    }
  },
  toStoreAppointment() {
    wx.navigateTo({
      url: '/packageE/appointment/store/storeAppointment/storeAppointment',
    })
  },
  toIndex() {
    wx.redirectTo({
      url: '/packageE/appointment/appointment_index'
    });
  },
  toList() {
    var str = JSON.stringify(this.data.appointmentLang);
    wx.redirectTo({
      url: '/packageE/appointment/ProjectList/ProjectList?appointmentLang=' + str,
    });
  },
  toclient() {
    wx.navigateTo({
      url: '/packageE/appointment/client/project/project'
    });
  },
  toAppiontment() {
    wx.navigateTo({
      url: '/packageE/appointment/client/appointment/appointment'
    });
  },
  toStore() {
    wx.navigateTo({
      url: "/packageE/appointment/technician/appointment_project/appointment_project?name=store"
    });
  },
  noStore() {
    wx.navigateTo({
      url: "/packageE/appointment/technician/appointment_project/appointment_project"
    });
  },
  toStoreTec() {
    wx.navigateTo({
      url: "/packageE/appointment/manager/stores_technician/stores_technician?store_id=" + this.data.mine.store_id
    });
  },
  toextension() {
    wx.navigateTo({
      url: "/packageG/pages/member/extension/extension"
    });
  },
  toWorker() {
    wx.navigateTo({
      url: "/packageE/appointment/technician/work_day/TechnicianWork/TechnicianWork?worker_id=" + this.data.mine.worker_id
    });
  },
  getMine() {
    let that = this;
    let urlStr = app.getNetAddresss("plugin.appointment.frontend.member.get-info");
    app._getNetWork({
      url: urlStr,
      data: {},
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            mine: res.data
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  }
});